<?php defined('IN_NWIDC') or exit('Access Invalid!');?>

<script src='/data/resource/layer/layer.js'></script>
<div class="page">
  <div class="fixed-bar">
    <div class="item-title">
      <h3><?php echo $lang['order_manage'];?></h3>
      <ul class="tab-base">
        <li><a href="JavaScript:void(0);" class="current"><span><?php echo $lang['manage'];?></span></a></li>
      </ul>
    </div>
  </div>
  <div class="fixed-empty"></div>
  <form method="get" action="index.php" name="formSearch" id="formSearch">
    <input type="hidden" name="act" value="order" />
    <input type="hidden" name="op" value="index" />
    <table class="tb-type1 noborder search">
      <tbody>
        <tr>
         <th><label><?php echo $lang['order_number'];?></label></th>
         <td><input class="txt2" type="text" name="order_sn" value="<?php echo $_GET['order_sn'];?>" /></td>
         <th><?php echo $lang['store_name'];?></th>
         <td><input class="txt-short" type="text" name="store_name" value="<?php echo $_GET['store_name'];?>" /></td>
         <th><label><?php echo $lang['order_state'];?></label></th>
          <td colspan=""><select name="order_state" class="querySelect">
              <option value=""><?php echo $lang['nc_please_choose'];?></option>
              <option value="10" <?php if($_GET['order_state'] == '10'){?>selected<?php }?>><?php echo $lang['order_state_new'];?></option>
              <option value="20" <?php if($_GET['order_state'] == '20'){?>selected<?php }?>><?php echo $lang['order_state_pay'];?></option>
              <option value="30" <?php if($_GET['order_state'] == '30'){?>selected<?php }?>><?php echo $lang['order_state_send'];?></option>
              <option value="40" <?php if($_GET['order_state'] == '40'){?>selected<?php }?>><?php echo $lang['order_state_success'];?></option>
              <option value="0" <?php if($_GET['order_state'] == '0'){?>selected<?php }?>><?php echo $lang['order_state_cancel'];?></option>
            </select></td>

            <th><label>订单类别</label></th>
            <td>
                <select name="order_type" class="querySelect">
                    <option value=""><?php echo $lang['nc_please_choose'];?></option>
                    <option value="is_whole" <?php if($_GET['order_type'] == 'is_whole'){?>selected<?php }?>>批发订单</option>
                    <option value="is_we_groupbuy" <?php if($_GET['order_type'] == 'is_we_groupbuy'){?>selected<?php }?>>微团订单</option>
                </select>
            </td>

        </tr>
        <tr>
          <th><label for="query_start_time"><?php echo $lang['order_time_from'];?></label></th>
          <td><input class="txt date" type="text" value="<?php echo $_GET['query_start_time'];?>" id="query_start_time" name="query_start_time">
            <label for="query_start_time">~</label>
            <input class="txt date" type="text" value="<?php echo $_GET['query_end_time'];?>" id="query_end_time" name="query_end_time"/></td>
         <th><?php echo $lang['buyer_name'];?></th>
         <td><input class="txt-short" type="text" name="buyer_name" value="<?php echo $_GET['buyer_name'];?>" /></td> <th>付款方式</th>
         <td>
            <select name="payment_code" class="w100">
            <option value=""><?php echo $lang['nc_please_choose'];?></option>
            <?php foreach($output['payment_list'] as $val) { ?>
            <option <?php if($_GET['payment_code'] == $val['payment_code']){?>selected<?php }?> value="<?php echo $val['payment_code']; ?>"><?php echo $val['payment_name']; ?></option>
            <?php } ?>
            </select>
         </td>
            <th>
                只显示保税订单
            </th>
            <td>
                <label for="" style='margin-right: 10px;'>
                    <input type="checkbox" name='tax_order' value='1' <?php if($_GET[tax_order] == 1){ echo 'checked';}?> >

                </label>
            </td>
          <td>

              <a href="javascript:void(0);" id="ncsubmit" class="btn-search " title="<?php echo $lang['nc_query'];?>">&nbsp;</a>

            </td>
            <td>
                <a href="/crontab/index.php?act=date" target="_blank" style="background-color: #f00;border-radius: 4px;padding:4px 6px;margin-left:14px;color:#fff;">
                    更新订单
                </a>
            </td>
        </tr>
      </tbody>
    </table>
  </form>
  <table class="table tb-type2" id="prompt">
    <tbody>
      <tr class="space odd">
        <th colspan="12"><div class="title"><h5><?php echo $lang['nc_prompts'];?></h5><span class="arrow"></span></div></th>
      </tr>
      <tr>
        <td>
        <ul>
            <li><?php echo $lang['order_help1'];?></li>
            <li><?php echo $lang['order_help2'];?></li>
            <li><?php echo $lang['order_help3'];?></li>
          </ul></td>
      </tr>
    </tbody>
  </table>
  <div style="text-align:right;"><a class="btns" target="_blank" href="index.php?<?php echo $_SERVER['QUERY_STRING'];?>&op=export_step1"><span><?php echo $lang['nc_export'];?>Excel</span></a></div>
  <table class="table tb-type2 nobdb">
    <thead>
      <tr class="thead">
        <th></th>
        <th><?php echo $lang['order_number'];?></th>
        <th><?php echo $lang['store_name'];?></th>
        <th><?php echo $lang['buyer_name'];?></th>
        <th class="align-center"><?php echo $lang['order_time'];?></th>
        <th class="align-center"><?php echo $lang['order_total_price'];?></th>
        <th class="align-center"><?php echo $lang['payment'];?></th>
        <th class="align-center"><?php echo $lang['order_state'];?></th>
        <th class="align-center"><?php echo $lang['nc_handle'];?></th>
      </tr>
    </thead>
    <tbody>
      <?php if(count($output['order_list'])>0){?>
      <?php foreach($output['order_list'] as $order){?>
      <tr class="hover">
        <td>
          <input type="checkbox" name='check' value='<?php echo $order['order_id']?>'>
        </td>
        <td><?php echo $order['order_sn'];?></td>
        <td><?php echo $order['store_name'];?></td>
        <td><?php echo $order['buyer_name'];?></td>
        <td class="nowrap align-center"><?php echo date('Y-m-d H:i:s',$order['add_time']);?></td>
        <td class="align-center"><?php echo $order['order_amount'];?></td>
        <td class="align-center"><?php echo orderPaymentName($order['payment_code']);?></td>
        <td class="align-center"><?php echo orderState($order);?></td>
        <td class="w144 align-center"><a href="index.php?act=order&op=show_order&order_id=<?php echo $order['order_id'];?>"><?php echo $lang['nc_view'];?></a>
        <!-- 取消订单 -->
    		<?php if($order['if_cancel']) {?>
        	| <a href="javascript:void(0)" onclick="if(confirm('<?php echo $lang['order_confirm_cancel'];?>')){location.href='index.php?act=order&op=change_state&state_type=cancel&order_id=<?php echo $order['order_id']; ?>'}">
        	<?php echo $lang['order_change_cancel'];?></a>
        	<?php }?>
        	<!-- 收款 -->
    		<?php if($order['if_system_receive_pay']) {?>
	        	| <a href="index.php?act=order&op=change_state&state_type=receive_pay&order_id=<?php echo $order['order_id']; ?>">
	        	<?php echo $lang['order_change_received'];?></a>
    		<?php }?>
          <?php if($order['is_joinpay_alloc'] == 0 && strpos($order["payment_code"], "joinpay") !== false) {?>
            | <a href="javascript:;" data-val="<?php echo $order['order_sn'];?>" class="joinPayAlloc">汇聚分账</a>
          <?php }?>
        	</td>
      </tr>
      <?php }?>
      <?php }else{?>
      <tr class="no_data">
        <td colspan="15"><?php echo $lang['nc_no_record'];?></td>
      </tr>
      <?php }?>
    </tbody>
    <tfoot>
      <tr class="tfoot">
        <td>
        <input type="checkbox" id='sel_all'>
        <script>
          $('#sel_all').click(function(event) {
            var checked = this.checked;
            $('[name=check]').each(function(){
              this.checked = checked;
            })
          });
        </script>
        </td>
        <td>
          <a class='btn' href="javascript:;" id='generate'>生成报文</a>
          <script>
            $('#generate').click(function(){
              var checked = $('[name=check]:checked').toArray();
              var ret = [];
              ret = checked.map(function(item){
                return item.value;
              });
              var index = layer.load();
              $.post('?act=order&op=record_order',{ids:ret},function(msg){
                layer.close(index);
                layer.msg(msg);
              })
            });
          </script>
          <a href="javascript:;" class='btn' onclick='alert("功能开发中")'>导入回执</a>
        </td>
        <td colspan="15" id="dataFuncs"><div class="pagination"> <?php echo $output['show_page'];?> </div></td>
      </tr>
    </tfoot>
  </table>
</div>

<script type="text/javascript" src="<?php echo RESOURCE_SITE_URL;?>/js/jquery-ui/jquery.ui.js"></script>
<script type="text/javascript" src="<?php echo RESOURCE_SITE_URL;?>/js/jquery-ui/i18n/zh-CN.js" charset="utf-8"></script>
<link rel="stylesheet" type="text/css" href="<?php echo RESOURCE_SITE_URL;?>/js/jquery-ui/themes/ui-lightness/jquery.ui.css"  />
<script type="text/javascript">
$(function(){
    $('#query_start_time').datepicker({dateFormat: 'yy-mm-dd'});
    $('#query_end_time').datepicker({dateFormat: 'yy-mm-dd'});
    $('#ncsubmit').click(function(){
    	$('input[name="op"]').val('index');$('#formSearch').submit();
    });
});

  $(".joinPayAlloc").click(function(){
    var orderSn = $(this).data("val");
    var layerIndex = layer.open({
      title:"请输入分账金额",
      content: '<input type="text" id="settleAmount">',
      yes: function(){
        var settleAmount = $("#settleAmount").val();
        layer.close(layerIndex);
        if(settleAmount == "" || settleAmount < 0){
          layer.msg("不能小于0");
          return;
        }
        $.ajax({
          type:"post",
          data: {
            orderSn: orderSn,
            settleAmount: settleAmount
          },
          url: "<?php echo WEB_DOMAIN;?>/pay/joinPayAlloc/pullOrder",
          success: function(res){
            if(res.state){
              layer.msg("受理成功！");
            }else{
              layer.msg(res.msg);
            }
          }
        })
      }
    });

  })
</script>
